<template>

  <van-cell-group>

    <van-cell v-for="item in list" :key="item.id" :title="item.name" :label="item.idCard">
      <template #right-icon>

        <van-button size="mini" type="primary" @click="edit(item.id)">修改</van-button>
        <van-button size="mini" type="danger" @click="removeById(item.id)">删除</van-button>
      </template>
    </van-cell>
  </van-cell-group>

</template>

<script>
import vaccinatorApi from '@/api/vaccinator'
import Cookies from 'js-cookie'
export default {
  name: 'List',
  data() {
    return {
      list: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      // 调用api
      vaccinatorApi.List(Cookies.get('Sysid'))
        .then(response => {
          this.list = response.data.rows
        })
    },
    edit(id) {
      const path = '/vaccinator/edit/' + id
      this.$router.push({
        path: path
      })
    },
    removeById(id) {
      vaccinatorApi.removeById(id).then((response) => {
        this.fetchData()
        this.$message.success(response.message)
      }).catch(error => {
        console.log('error', error)
      })
    }

  }
}
</script>

<style scoped>

</style>
